<?php
$catid = 0;
if($_GET['CatId'])
	$catid = $_GET['CatId'];
$keyword = '';
if($_GET['Keywords'])
	$keyword = $_GET['Keywords'];
$page = $_GET['Page'];
if(!$page)
	$page = 1;
//echo $blogid;
$postlist = $blog->GetPostList($blogid, $catid, $keyword, '', 0, $page, $blog->pagesize);
$postcount = $blog->GetPostCount($blogid, $catid, $keyword, '', 0);
$pagecount = ceil($postcount/$blog->pagesize);
if(!$pagecount)
	$pagecount = 1;
$cat = $blog->GetCatList($blogid, 'ee_blog_categories2');
?>
<script type="text/javascript">
function getURL(formId){
	var formE = document.getElementById(formId);
	//console.log(formValue);
	if(formE.tagName == 'INPUT'){
		formEValue = formE.value;
	} else {
		formEValue = formE.options[formE.selectedIndex].value;
	}
	window.location = 'index.php?Action=PostList&'+formId+'='+formEValue;
	return false;//why?
}
</script>
<div class="tab-content show" id="chapter-manage">
<a href="index.php?Action=Post">写文章</a>
<a class="current" href="index.php?Action=PostList">文章列表</a>
</div>
</div>
<div id="content"><div class="admin-form">
<h3>文章列表</h3>
<form action="" method="post" name="search-keywords" id="search-article" onsubmit="javascript: return getURL('Keywords')">
 <fieldset>
	<legend>关键字搜索</legend>
	<input type="text" name="keywords" id="Keywords" />
	<input type="submit" name="submit-key" value="搜索" />
 </fieldset>
</form>

<form action="" method="post" name="search-cat" id="search-article" onsubmit="javascript: return getURL('CatId')">
 <fieldset>
	<legend>分类搜索</legend>
	<select name="CatId" id="CatId">
		<option value="0" selected="selected">All</option>
		<?php
			foreach($cat as $value){
				echo "<option value=\"".$value[F_ID]."\">".$value[F_CATEGORIES_NAME]."</option>";
			}
		?>
	</select>
	<input type="submit" name="submit-key" value="搜索" />
 </fieldset>
</form>
<table>
  <thead>
    <tr>
      <th>ID</th>
      <th>时间</th>
      <th>标题</th>
      <th>分类</th>
      <th>评论</th>
      <th colspan="3">操作</th>
    </tr>
  </thead>
  <tbody>
<?php
if($postlist){
	foreach($postlist as $value)
	{
?>
  	<tr>
      <td><?php echo $value['F_ID'] ?></td>
      <td><?php echo date('Y-m-d H:i', $value['F_POSTS_ISSUE_DATE']) ?></td>
      <td><?php echo $value['F_POSTS_TITLE'] ?></td>
      <td><?php echo $value['F_CATEGORIES_NAME'] ?></td>
      <td><a href="index.php?Action=Comments&PostId=<?php echo $value['F_ID'] ?>"><?php echo $value['F_POSTS_COMMENTS'] ?></a></td>
      <td><a href="../index.php?Post=<?php echo $value['F_ID'] ?>&Action=Post" target="_blank">查看</a></td>
      <td><a href="index.php?Action=Post&PostId=<?php echo $value['F_ID'] ?>">编辑</a></td>
      <td><a onclick="return confirm('真的要删除吗？');" href="index.php?Action=PostDel&PostId=<?php echo $value['F_ID']?>">删除</a></td>
	</tr>
<?php
	}
}
?>
  </tbody>
</table>

<div class="pagination"><?php echo Page($pagecount,$page,$blog->pagesize, $postcount)?></div>
</div></div>